<template>
  <view class="xmain">
    <headBar :title="appTitle"></headBar>
    <view class="qTab">
      <view class="uni-flex uni-row kemuTitleHead">
        <view class="flex-item">
          <view @click="selectTab(0,true)" :class="tabIndex == 0 ? 'kemuTitleHeadFocus':''">科目一</view>
        </view>
        <view class="flex-item">
          <view @click="selectTab(1,true)" :class="tabIndex == 1 ? 'kemuTitleHeadFocus':''">科目四</view>
        </view>
      </view>
    </view>
    <view style="height: 40rpx;"></view>
    <view class="qContent">
      <view class="qContentLine uni-flex uni-row">
        <view class="qContentLineFlex flex-item">
          <view class=" uni-flex uni-column">
            <view class="flex-item flex-item-V iconRow" @click="indexDirect('/pages/question/question?subject='+(tabIndex == 0?1:4)+'&model='+model)">
              <uni-icons type="calendar" size="50rpx" color="#3495fc"></uni-icons>
              <view class="iconTitle">随机练习</view>
            </view>
            <view class="flex-item flex-item-V iconRow" @click="indexDirect('/pages/collect/lst')">
              <uni-icons type="star-filled" size="50rpx" color="#3495fc"></uni-icons>
              <view class="iconTitle">收藏题目</view>
            </view>
          </view>
        </view>
        <view class="qContentLineFlex flex-item">
          <view class=" uni-flex uni-column">
            <view class="flex-item flex-item-V circleRow" @click="indexDirect('/pages/sort/sort')">
              <view class="textContent" style="background: #05c0a3;border:5px solid #53ddc8;">
                <view style="height:45rpx;"></view>
                <view>顺序练习</view>
                <view>{{alreadyNum}}/{{totalNum}}</view>
              </view>
            </view>
            <view class="flex-item flex-item-V circleRow" @click="indexDirect('/pages/examin/examin?subject='+subject)">
              <view class="textContent" style="background: #ff6c41;border:5px solid #ff9453;">
                <view style="height:45rpx;"></view>
                <view>模拟考试</view>
                <view>仿真冲刺</view>
              </view>
            </view>
          </view>
        </view>
        <view class="qContentLineFlex flex-item">
          <view class=" uni-flex uni-column">
            <view class="flex-item flex-item-V iconRow" @click="indexDirect('/pages/wrong/lst')">
              <uni-icons type="close" size="50rpx" color="#3495fc"></uni-icons>
              <view class="iconTitle">错题收集</view>
            </view>
            <view class="flex-item flex-item-V iconRow" @click="resetQt()">
              <uni-icons type="refreshempty" size="50rpx" color="#3495fc"></uni-icons>
              <view class="iconTitle">题目重置</view>
            </view>
          </view>
        </view>
      </view>
    </view>
    <view style="height: 80rpx;"></view>
    <view class="checkQt">
      <view class="uni-flex uni-rows" @click="indexDirect('/pages/sign/sign')">
        <view class="flex-item" style="width:150rpx;">
          <image :src="'../../static/app_image/'+carType+'.png'" style="width:80rpx;height:80rpx;"></image>
        </view>
        <view class="flex-item">
          当前题库:
        </view>
        <view class="flex-item" style="margin-left: 20rpx;">
          {{currentCar.alias}}
        </view>
        <view class="flex-item" style="margin-left: 80rpx;">
          选择题库<uni-icons type="plus-filled"  color="#FFFFFF"></uni-icons>
        </view>
      </view>
    </view>
    <xToastAgree v-if="DialogShow" :isShow="DialogShow">
      <view class="" style="background: #FFFFFF;border-radius: 10rpx;width:70%;margin: 0rpx auto;padding:60rpx;">
        <view style="text-align: center;font-weight: bold">温馨提示</view>
        <view style="margin-top: 20rpx;">
          欢迎使用本产品！本产品非常重视您的隐私和个人信息。在您使用本产品前，请认真阅读
          <text style="color:#3495fc;" @click="x_redirect('/pages/content/content?type=agreement')">《用户协议》</text>
          以及<text style="color:#3495fc;" @click="x_redirect('/pages/content/content?type=privacy')">《隐私政策》</text>,
          您接受并同意条款后即可开始使用本产品
        </view>
        <view style="margin-top:20rpx;">
          <button type="primary" @click="agree()">同意并继续</button>
        </view>
        <view style="margin-top:20rpx;">
          <button style="background: #dedede;" @click="noAgree()">不同意仅浏览模式</button>
        </view>
      </view>
    </xToastAgree>
    <bootNav v-if="isAgree" nav="home"></bootNav>
  </view>

</template>

<script>
export default {

  data() {
    return {
      fangji:[],
      current_page:'',
      share:{
        title:this.appName,
        path:'/pages/index/index',
        imageUrl:'',
        desc:'',
        content:''
      },
      tabIndex:0,
      carType:'xiaoche',
      cheTypeList:{
        xiaoche:{alias:"小车",remark:"C1/C2/C3",model:"c1"},
        huoche:{alias:"货车",remark:"A2/B2",model:"a2"},
        keche:{alias:"客车",remark:"A1/A3/B1",model:"a1"},
        motoche:{alias:"摩托车",remark:"D/E/F",model:"d"},
      },
      totalNumList: {
        'c1':1323,
        'a1':3101,
        'a2':3109,
        'd':400,
        '4':1236
      },
      currentCar:{alias:"", remark:""},
      totalNum:0,
      alreadyNum:1,
      cacheSortTotalIndexKey:'cacheSortTotalIndex',
      subject:1,
      model:'',
      DialogShow:false,
      isAgree:false
    }
  },
  onShareAppMessage() {
    return {
      title: this.title,
    }
  },
  onShareTimeline: function() {
    return {
      title: this.title,
    }
  },
  onLoad(e) {
    var t = this;
    var carType = t.carType;
    var cheTypeList = t.cheTypeList;
    var storgeCarType = t.xCacheGet('carType');
    if(storgeCarType){
      carType = storgeCarType;
      t.carType = carType;
    }else{
      t.xCacheSet('carType',carType);
    }
    var currentCar = cheTypeList[carType];
    t.currentCar = currentCar;
    var totalNumList = t.totalNumList;
    var totalNum = totalNumList[currentCar['model']];
    t.totalNum = totalNum;
    var tab = 0;
    if(e.tab){
      tab = e.tab;
      tab = tab == 1 ? 1: 0;
    }
    t.tabIndex = tab;
    t.selectTab(tab);
    t.getAgree();
  },
  methods: {
    selectTab(tabIndex,isDump){
      var t = this;
      if(!isDump){
        t.tabIndex = tabIndex;
        var currentCar = t.currentCar;
        var totalNumList = t.totalNumList;
        var totalNum = totalNumList[currentCar['model']];
        t.totalNum = totalNum;
        t.model = currentCar['model'];
        var cacheSortTotalIndex = t.xCacheGet(t.cacheSortTotalIndexKey);
        var subject = tabIndex === 0 ? 1 :4;
        t.subject = subject;
        if(cacheSortTotalIndex && cacheSortTotalIndex[currentCar.model+'_'+subject]){
          t.alreadyNum = cacheSortTotalIndex[currentCar.model+'_'+subject];
        }else{
          t.alreadyNum = 1;
        }

      }else{
        t.indexDirect('/pages/index/index?tab='+tabIndex)
      }
    },
    // 重置随机题库
    resetQt(){
      var t = this;
      var cheTypeList = t.cheTypeList;
      for(var i = 1;i<=10;i++){
        for(var x in cheTypeList){
          var cheType = cheTypeList[x];
          var key1 = 'rand_'+cheType['model']+'_1'+'_'+i;
          var key2 = 'rand_'+cheType['model']+'_4'+'_'+i;
          uni.removeStorage({key:key1});
          uni.removeStorage({key:key2});
        }
      }
      uni.showToast({title: '已刷新题库', icon: 'success', duration: 2000})
    },
    getAgree(){
      var t =this;
      var agree = t.xCacheGet('isAgreement');
      if(!agree){
        t.DialogShow = true;
        t.isAgree = false;
      }else{
        t.isAgree = true;
      }
    },
    agree(){
      var t =this;
      t.xCacheSet('isAgreement',true);
      t.DialogShow = false;
      t.isAgree = true;
    },
    noAgree(){
      var t =this;
      t.xCacheSet('isAgreement',false);
      t.DialogShow = false;
      t.isAgree = false;
    },
    indexDirect(targetPage){
      var t =this;
      var agree = t.xCacheGet('isAgreement');
      if(!agree){
        t.DialogShow = true;
      }else{
        t.DialogShow = false;
        t.x_redirect(targetPage);
      }
    }
  }
}
</script>

<style>
@import "../index/index.css";
</style>
